﻿using System;
using System.Collections.Generic;
using MyAMS.WebServer.Models;

namespace MyAMS.WebServer.ViewModels
{
    /// <summary>
    /// 视图模型基类
    /// </summary>
    public class BaseViewModel
    {
        private readonly Dictionary<Type, object> modelItems = new Dictionary<Type, object>();

        /// <summary>
        /// 获取或设置反伪造令牌
        /// </summary>
        public AntiForgeryToken AntiForgeryToken { get; set; }
        
        /// <summary>
        /// 获取或设置容器
        /// </summary>
        public NamedEntity Container { get; set; }

        ///// <summary>
        ///// 获取或设置站点视图模型
        ///// </summary>
        //public ViewModelItem<Node> Site { get; set; }
        //TODO (5he11)
        ///// <summary>
        ///// 获取或设置用户视图模型
        ///// </summary>
        //public UserViewModel User { get; set; }

        /// <summary>
        /// 添加一个视图模型
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="modelItem">视图模型</param>
        public void AddModelItem<T>(T modelItem) where T : class
        {
            modelItems[typeof(T)] = modelItem;
        }

        /// <summary>
        /// 获取视图模型
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <returns>视图模型</returns>
        public T GetModelItem<T>() where T : class
        {
            if (modelItems.ContainsKey(typeof(T)))
            {
                return modelItems[typeof(T)] as T;
            }
            return null;
        }
    }
}
